package com.zut.yyzx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zut.yyzx.dto.CustomerPreferenceDTO;
import com.zut.yyzx.pojo.Customerpreference;
import com.zut.yyzx.service.CustomerpreferenceService;
import com.zut.yyzx.utils.ResultVo;
import com.zut.yyzx.vo.CustomerPreferenceVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/customerpreference")
@CrossOrigin
//"客户喜好管理"
public class CustomerpreferenceController {
    @Resource
    private CustomerpreferenceService customerpreferenceService;

    @PostMapping("/addCustomerperference")
    //"为顾客单个添加喜好"
    public ResultVo addCustomerperference(Customerpreference customerperference) throws Exception{
        customerpreferenceService.save(customerperference);
        return ResultVo.ok("添加顾客喜好");
    }

    //"更新顾客喜好"
    @PostMapping("/updateCustomerpreference")
    public ResultVo updateCustomerpreference(Customerpreference customerpreference) throws Exception{
        customerpreferenceService.updateById(customerpreference);
        return ResultVo.ok("更新顾客喜好");
    }

    //"删除顾客喜好"
    @GetMapping("/removeCustomerpreference")
    public ResultVo removeCustomerpreference(Integer id) throws Exception{
        customerpreferenceService.removeById(id);
        return ResultVo.ok("删除顾客喜好");
    }

    @GetMapping("/listCustomerpreferencePage")
    //"顾客喜好查询（分页）/可以根据顾客姓名查询"
    public ResultVo<Page<CustomerPreferenceVo>> listCustomerpreferencePage(CustomerPreferenceDTO customerPreferenceDTO) throws Exception{
        return customerpreferenceService.listCustomerPreferenceVoPage(customerPreferenceDTO);
    }
}
